package io.renren.modules.canteens.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.canteens.dao.FoodDao;
import io.renren.modules.canteens.dto.FoodDTO;
import io.renren.modules.canteens.entity.FoodEntity;
import io.renren.modules.canteens.service.FoodService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 食材表（辅材共用）
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Service
public class FoodServiceImpl extends CrudServiceImpl<FoodDao, FoodEntity, FoodDTO> implements FoodService {
    @Autowired
    private  FoodDao foodDao;
    @Override
    public QueryWrapper<FoodEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<FoodEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public FoodDTO getName(String name) {
        FoodDTO foodDTO = foodDao.getName(name);
        return foodDTO;
    }

    @Override
    public PageData<FoodDTO> getFood(Map<String, Object> params) {
        String foodName = (String)params.get("foodName");
        QueryWrapper<FoodEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(foodName), "food_name", foodName);
        IPage<FoodEntity> page = baseDao.selectPage(
                getPage(params, null, false),
                wrapper);
        PageData<FoodDTO> pageData = getPageData(page, FoodDTO.class);
        return pageData;
    }

    @Override
    public List<FoodDTO> getLikeName(String name) {
        List<FoodDTO> likeName = foodDao.getLikeName(name);
        return likeName;
    }
}